package cn.edu.hunau.java.week01.day03;

import org.junit.Test;

import java.util.Random;
import java.util.Scanner;

public class GuessTest {
    @Test
    public void test(){
        Random r=new Random();
        int num=r.nextInt(100)+1;
        Scanner sc=new Scanner(System.in);
        int count=0;
        System.out.println(num);
        while(true){
            count++;
            System.out.print("请输入猜的数字: ");
            int i=sc.nextInt();
            if(i>num){
                System.out.println("猜的数字太大了");
            }else if(i<num){
                System.out.println("猜的数字太小了");
            }else{
                System.out.println("恭喜你猜对了,一共猜了"+count+"次");
                break;
            }
        }
    }
}
